#pragma once
#include <Windows.h>
#include <bitset>
#include <vector>
#include "BackupFSDefines.h"
namespace BackupFS
{

	/*
	Current use the class BackupFSBitmap
	The class BackupFSBit is just for comparation for the class BackupFSBitmap
	std::bitset is not flexible
	1 bit represents 4K size, and the total represents 100G
	*/
	class BackupFSBit
	{
	public:
		BackupFSBit(LONGLONG index);
		~BackupFSBit();
		void Set(LONGLONG offset, LONGLONG length);
		bool IsSet(LONGLONG offset) const;
	private:
		std::bitset<BACKUPFS_BITMAP_SIZE> _Bits;
		/*
		0:0-100G
		1:100-200G
		2:200-300G
		*/
		LONGLONG _Index;
	};
	class BackupFSBitmap
	{
	public:
		BackupFSBitmap(const std::wstring &DataPath, bool SaveToFile, LONGLONG Index, LONGLONG BlockSize = BACKUPFS_PAGE_SIZE);
		virtual ~BackupFSBitmap();
		void Set(LONGLONG offset, LONGLONG length);
		bool IsSet(LONGLONG offset);
		unsigned char* Data() { return _Data.data(); }
		LONGLONG Length() { return _Length; }

	private:
		void _OpenFiles();
		bool _IsSet(const unsigned char c, const unsigned int bit)
		{
			if ((c & (0x80 >> bit)) > 0)
				return true;
			return false;
		}
		std::vector<unsigned char> _Data;
		LONGLONG _BlockSize;
		LONGLONG _Length;
		LONGLONG _Index;
		std::wstring _Path;
		//save the bitmap information to file
		//use map file for performance
		HANDLE _File = INVALID_HANDLE_VALUE;
		HANDLE _MappingFile = INVALID_HANDLE_VALUE;
		LPVOID _MapView = nullptr;
		bool _SaveToFile = false;
	};
}

